package com.sqsf.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {
    @Pointcut("execution(* com.sqsf.aop.*.*(..))")

    public void pointcut(){}

    @Before("pointcut()")
    public void before(){
        System.out.println("前置通知...");
    }
    @After("pointcut()")
    public void after(){
        System.out.println("后置通知");
    }
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知");
        Object[] args = joinPoint.getArgs();
        Object proceed = joinPoint.proceed(args);
        System.out.println("环绕通知");
        return proceed;
    }
    @AfterThrowing(value = "pointcut()",throwing = "e")
    public void afterThrowing(Exception e){
        System.out.println("异常通知");
    }
    @AfterReturning(value = "pointcut()",returning = "res")
    public void afterReturning(Object res){
        System.out.println("返回通知");
    }

}
